package com.cyz.service.impl;

import java.sql.SQLException;
import java.util.List;

import com.cyz.dao.ShopcartDao;
import com.cyz.dao.impl.ShopcartDaoImpl;
import com.cyz.pojo.Shopcart;
import com.cyz.service.ShopcartService;

public class ShopcartServiceImpl implements ShopcartService{

	private static final Exception ShopcartExsit = null;
	@Override
	/**
	 * ͨ���û�ID����ȡ���Ĺ��ﳵ��Ϣ
	 * @param UseId
	 * @return
	 * @throws SQLException
	 */
	public List<Shopcart> getShopcartByUseId(Integer useId) throws SQLException {
		// TODO Auto-generated method stub
		ShopcartDao shopcartDao=new ShopcartDaoImpl();
		return shopcartDao.getShopcartByUseId(useId);
	}

	@Override
	/**
	 * ��ǰ��Ʒ���빺�ﳵ
	 * @param userId
	 * @param productId
	 * @param amount
	 * @param price
	 * @throws SQLException
	 */
	public void insertShopcart(Integer userId, Integer productId, Integer amount, float price) throws Exception {
		ShopcartDao shopcartDao=new ShopcartDaoImpl();
		
		Integer temp=shopcartDao.IsExist(userId, productId);

		
		if(temp>0)
		{	
			Integer total=null;
			total=temp+amount;
			
			shopcartDao.updateShopcart(userId, productId,total);
		}
		if(temp==0)
		{
			shopcartDao.insertShopcart(userId, productId,amount, price);
		}
		
		
	}
	//////////////////

	@Override
	public void deteleShopcart(String userName, String productName) {
		ShopcartDao shopcartDao = new ShopcartDaoImpl();
		shopcartDao.deteleShopcart(userName, productName);
		//shopcartDao.de
		
	}

	@Override
	public void updateShopcart(Integer userId, Integer productId, Integer amount) {
		// TODO Auto-generated method stub
		ShopcartDao shopcartDao = new ShopcartDaoImpl();
		shopcartDao.updateShopcart(userId, productId, amount);
		
	}
	/**
	 * 清空该用户购物车
	 * @param userName
	 * @param productName
	 */
	public void deteleAllShopcart(Integer userId)
	{
		ShopcartDao shopcartDao = new ShopcartDaoImpl();
		shopcartDao.deteleAllShopcart(userId);
	}

}
